<?php


namespace app\admin\controller\v1;


use app\admin\model\StatisticsModel;
use app\admin\service\StatisticsService;
use app\admin\Validate\statistics\GetArticleStatisticsValidate;
use app\BaseController;
use app\common\Token;
use app\common\validate\IdMustIntValidate;
use app\common\validate\PageLimitValidate;

/**
 * 统计
 * Class Statistics
 * @package app\admin\controller\v1
 */
class Statistics extends BaseController
{
    /**
     * 获取每天的点击统计
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function getStatisticsList() {
        Token::checkToken($this->request);
        $param = (new PageLimitValidate())->validateParam();
        $result = (new StatisticsModel())->toPaginate($param);
        return successJson($result);
    }

    /**
     * 通过statistics_id获取文章的点击详情
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function articleStatisticsDetails() {
        Token::checkToken($this->request);
        $param = (new GetArticleStatisticsValidate())->validateParam();
        $result = (new StatisticsService())->getArticleStatisticsDetails($param);
        return successJson($result);
    }

    /**
     * 通过statistics_id获取广告的点击详情
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function adStatisticsDetails() {
        Token::checkToken($this->request);
        $param = (new GetArticleStatisticsValidate())->validateParam();
        $result = (new StatisticsService())->getAdStatisticsDetails($param);
        return successJson($result);
    }

    /**
     * 获取今天的文章点击
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function todayArticleStatisticsDetails() {
//        Token::checkToken($this->request);
        $param = (new PageLimitValidate())->validateParam();
        $result = (new StatisticsService())->getTodayArticleStatistics($param);
        return successJson($result);
    }

    /**
     * 获取今天的广告点击
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function todayAdStatisticsDetails() {
//        Token::checkToken($this->request);
        $param = (new PageLimitValidate())->validateParam();
        $result = (new StatisticsService())->getTodayAdStatistics($param);
        return successJson($result);
    }

}